/*******************************************************************************
 * This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     Peter Smith
 *******************************************************************************/

#include "SheetGenerator.h"
#include "XLUtil.h"

// Admin function names
#define AF_GET_MENU     "org.boris.xlloop.GetMenu"
#define AF_EXEC_COMMAND "org.boris.xlloop.ExecuteCommand"

namespace
{
	// Store a reference to the protocol 
	Protocol* g_protocol;

	// The list of static function names
	#define MAX_COMMANDS 512
	static char* g_cmdNames[MAX_COMMANDS];
	static int g_cmdCount = 0;

	// Our standard error message
	static XLOPER g_errorMessage;
}

char* RegisterCommand(LPXLOPER xllName, const char* menu, const char* submenu, const char* item)
{
	char temp[512];
	char tmp2[10];
	if(submenu) {
		sprintf(temp, "%s:%s:%s", menu, submenu, item);
	} else {
		sprintf(temp, "%s:%s", menu, item);
	}
	sprintf(tmp2, "FSC%d", g_cmdCount);
	XLUtil::RegisterCommand(xllName, tmp2, "", tmp2, "", "3", "", "");
	g_cmdNames[g_cmdCount] = strdup(temp);
	g_cmdCount++;
	return strdup(tmp2);
}

MENU_ITEM* GenerateMenu(LPXLOPER xllName, char* menuName, char* subMenu, LPXLOPER items)
{
	int itemCount = items->val.array.rows;
	MENU_ITEM* mi = (MENU_ITEM*) malloc(sizeof(MENU_ITEM) * (itemCount + 1));
	mi[0].menuName = menuName;
	mi[0].helpText = "";
	mi[0].menuCommand = "";
	for(int i = 0; i < itemCount; i++) {
		LPXLOPER x = &items->val.array.lparray[i];
		mi[i+1].menuName = XLMap::getNTString(x, "name");
		mi[i+1].helpText = XLMap::getNTString(x, "help");
		mi[i+1].menuCommand = RegisterCommand(xllName, menuName, subMenu, mi[i+1].menuName);
	}
	return mi;
}

void SheetGenerator::Execute(Protocol* protocol, const char* name)
{
	XLOPER mn;
	mn.xltype = xltypeStr;
	mn.val.str = XLUtil::MakeExcelString(name);
	LPXLOPER res = protocol->execute(AF_EXEC_COMMAND, false, 1, &mn);
	free(mn.val.str);
	XLUtil::FreeContents(res);
}

void SheetGenerator::Register(LPXLOPER xllName, Protocol* protocol, dictionary* ini)
{
	// Need to save a reference for commands
	g_protocol = protocol;

	LPXLOPER res = protocol->execute(AF_GET_MENU, true, 0);
	if(!res) 
		return;

	char* menuName = XLMap::getNTString(res, "name");
	if(!menuName) {
		XLUtil::FreeContents(res);
		return;
	}

	LPXLOPER items = XLMap::get(res, "items");
	if(!items) {
		XLUtil::FreeContents(res);
		return;
	}

	MENU_ITEM* toplevel = GenerateMenu(xllName, menuName, NULL, items);
	XLUtil::AddMenu(xllName, toplevel, items->val.array.rows+1, "Help");

	LPXLOPER submenus = XLMap::get(res, "submenus"); 
	int subc = submenus->val.array.rows;
	int posCount = 1;
	for(int i = 0; i < subc; i++) {
		LPXLOPER x = &submenus->val.array.lparray[i];
		char* mn = XLMap::getNTString(x, "name");
		LPXLOPER im = XLMap::get(x, "items");
		MENU_ITEM* mis = GenerateMenu(xllName, menuName, mn, im);
		int pos = posCount;
		int p = XLMap::getInteger(x, "position");
		if(p != -1) {
			pos = p;
		} else {
			posCount++;
		}
		XLUtil::AddMenu(xllName, mis, im->val.array.rows+1, menuName, (char*) pos);
	}
}

void WINAPI FSExecCmdNumber(int number)
{
	if(g_cmdCount < number) {
		return;
	}
	SheetGenerator::Execute(g_protocol, g_cmdNames[number]);
}

#define DECLARE_EXCEL_COMMAND(number) \
__declspec(dllexport) void WINAPI FSC##number () \
{ \
	FSExecCmdNumber(number); \
} 

DECLARE_EXCEL_COMMAND(0)
DECLARE_EXCEL_COMMAND(1)
DECLARE_EXCEL_COMMAND(2)
DECLARE_EXCEL_COMMAND(3)
DECLARE_EXCEL_COMMAND(4)
DECLARE_EXCEL_COMMAND(5)
DECLARE_EXCEL_COMMAND(6)
DECLARE_EXCEL_COMMAND(7)
DECLARE_EXCEL_COMMAND(8)
DECLARE_EXCEL_COMMAND(9)
DECLARE_EXCEL_COMMAND(10)
DECLARE_EXCEL_COMMAND(11)
DECLARE_EXCEL_COMMAND(12)
DECLARE_EXCEL_COMMAND(13)
DECLARE_EXCEL_COMMAND(14)
DECLARE_EXCEL_COMMAND(15)
DECLARE_EXCEL_COMMAND(16)
DECLARE_EXCEL_COMMAND(17)
DECLARE_EXCEL_COMMAND(18)
DECLARE_EXCEL_COMMAND(19)
DECLARE_EXCEL_COMMAND(20)
DECLARE_EXCEL_COMMAND(21)
DECLARE_EXCEL_COMMAND(22)
DECLARE_EXCEL_COMMAND(23)
DECLARE_EXCEL_COMMAND(24)
DECLARE_EXCEL_COMMAND(25)
DECLARE_EXCEL_COMMAND(26)
DECLARE_EXCEL_COMMAND(27)
DECLARE_EXCEL_COMMAND(28)
DECLARE_EXCEL_COMMAND(29)
DECLARE_EXCEL_COMMAND(30)
DECLARE_EXCEL_COMMAND(31)
DECLARE_EXCEL_COMMAND(32)
DECLARE_EXCEL_COMMAND(33)
DECLARE_EXCEL_COMMAND(34)
DECLARE_EXCEL_COMMAND(35)
DECLARE_EXCEL_COMMAND(36)
DECLARE_EXCEL_COMMAND(37)
DECLARE_EXCEL_COMMAND(38)
DECLARE_EXCEL_COMMAND(39)
DECLARE_EXCEL_COMMAND(40)
DECLARE_EXCEL_COMMAND(41)
DECLARE_EXCEL_COMMAND(42)
DECLARE_EXCEL_COMMAND(43)
DECLARE_EXCEL_COMMAND(44)
DECLARE_EXCEL_COMMAND(45)
DECLARE_EXCEL_COMMAND(46)
DECLARE_EXCEL_COMMAND(47)
DECLARE_EXCEL_COMMAND(48)
DECLARE_EXCEL_COMMAND(49)
DECLARE_EXCEL_COMMAND(50)
DECLARE_EXCEL_COMMAND(51)
DECLARE_EXCEL_COMMAND(52)
DECLARE_EXCEL_COMMAND(53)
DECLARE_EXCEL_COMMAND(54)
DECLARE_EXCEL_COMMAND(55)
DECLARE_EXCEL_COMMAND(56)
DECLARE_EXCEL_COMMAND(57)
DECLARE_EXCEL_COMMAND(58)
DECLARE_EXCEL_COMMAND(59)
DECLARE_EXCEL_COMMAND(60)
DECLARE_EXCEL_COMMAND(61)
DECLARE_EXCEL_COMMAND(62)
DECLARE_EXCEL_COMMAND(63)
DECLARE_EXCEL_COMMAND(64)
DECLARE_EXCEL_COMMAND(65)
DECLARE_EXCEL_COMMAND(66)
DECLARE_EXCEL_COMMAND(67)
DECLARE_EXCEL_COMMAND(68)
DECLARE_EXCEL_COMMAND(69)
DECLARE_EXCEL_COMMAND(70)
DECLARE_EXCEL_COMMAND(71)
DECLARE_EXCEL_COMMAND(72)
DECLARE_EXCEL_COMMAND(73)
DECLARE_EXCEL_COMMAND(74)
DECLARE_EXCEL_COMMAND(75)
DECLARE_EXCEL_COMMAND(76)
DECLARE_EXCEL_COMMAND(77)
DECLARE_EXCEL_COMMAND(78)
DECLARE_EXCEL_COMMAND(79)
DECLARE_EXCEL_COMMAND(80)
DECLARE_EXCEL_COMMAND(81)
DECLARE_EXCEL_COMMAND(82)
DECLARE_EXCEL_COMMAND(83)
DECLARE_EXCEL_COMMAND(84)
DECLARE_EXCEL_COMMAND(85)
DECLARE_EXCEL_COMMAND(86)
DECLARE_EXCEL_COMMAND(87)
DECLARE_EXCEL_COMMAND(88)
DECLARE_EXCEL_COMMAND(89)
DECLARE_EXCEL_COMMAND(90)
DECLARE_EXCEL_COMMAND(91)
DECLARE_EXCEL_COMMAND(92)
DECLARE_EXCEL_COMMAND(93)
DECLARE_EXCEL_COMMAND(94)
DECLARE_EXCEL_COMMAND(95)
DECLARE_EXCEL_COMMAND(96)
DECLARE_EXCEL_COMMAND(97)
DECLARE_EXCEL_COMMAND(98)
DECLARE_EXCEL_COMMAND(99)
DECLARE_EXCEL_COMMAND(100)
DECLARE_EXCEL_COMMAND(101)
DECLARE_EXCEL_COMMAND(102)
DECLARE_EXCEL_COMMAND(103)
DECLARE_EXCEL_COMMAND(104)
DECLARE_EXCEL_COMMAND(105)
DECLARE_EXCEL_COMMAND(106)
DECLARE_EXCEL_COMMAND(107)
DECLARE_EXCEL_COMMAND(108)
DECLARE_EXCEL_COMMAND(109)
DECLARE_EXCEL_COMMAND(110)
DECLARE_EXCEL_COMMAND(111)
DECLARE_EXCEL_COMMAND(112)
DECLARE_EXCEL_COMMAND(113)
DECLARE_EXCEL_COMMAND(114)
DECLARE_EXCEL_COMMAND(115)
DECLARE_EXCEL_COMMAND(116)
DECLARE_EXCEL_COMMAND(117)
DECLARE_EXCEL_COMMAND(118)
DECLARE_EXCEL_COMMAND(119)
DECLARE_EXCEL_COMMAND(120)
DECLARE_EXCEL_COMMAND(121)
DECLARE_EXCEL_COMMAND(122)
DECLARE_EXCEL_COMMAND(123)
DECLARE_EXCEL_COMMAND(124)
DECLARE_EXCEL_COMMAND(125)
DECLARE_EXCEL_COMMAND(126)
DECLARE_EXCEL_COMMAND(127)
DECLARE_EXCEL_COMMAND(128)
DECLARE_EXCEL_COMMAND(129)
DECLARE_EXCEL_COMMAND(130)
DECLARE_EXCEL_COMMAND(131)
DECLARE_EXCEL_COMMAND(132)
DECLARE_EXCEL_COMMAND(133)
DECLARE_EXCEL_COMMAND(134)
DECLARE_EXCEL_COMMAND(135)
DECLARE_EXCEL_COMMAND(136)
DECLARE_EXCEL_COMMAND(137)
DECLARE_EXCEL_COMMAND(138)
DECLARE_EXCEL_COMMAND(139)
DECLARE_EXCEL_COMMAND(140)
DECLARE_EXCEL_COMMAND(141)
DECLARE_EXCEL_COMMAND(142)
DECLARE_EXCEL_COMMAND(143)
DECLARE_EXCEL_COMMAND(144)
DECLARE_EXCEL_COMMAND(145)
DECLARE_EXCEL_COMMAND(146)
DECLARE_EXCEL_COMMAND(147)
DECLARE_EXCEL_COMMAND(148)
DECLARE_EXCEL_COMMAND(149)
DECLARE_EXCEL_COMMAND(150)
DECLARE_EXCEL_COMMAND(151)
DECLARE_EXCEL_COMMAND(152)
DECLARE_EXCEL_COMMAND(153)
DECLARE_EXCEL_COMMAND(154)
DECLARE_EXCEL_COMMAND(155)
DECLARE_EXCEL_COMMAND(156)
DECLARE_EXCEL_COMMAND(157)
DECLARE_EXCEL_COMMAND(158)
DECLARE_EXCEL_COMMAND(159)
DECLARE_EXCEL_COMMAND(160)
DECLARE_EXCEL_COMMAND(161)
DECLARE_EXCEL_COMMAND(162)
DECLARE_EXCEL_COMMAND(163)
DECLARE_EXCEL_COMMAND(164)
DECLARE_EXCEL_COMMAND(165)
DECLARE_EXCEL_COMMAND(166)
DECLARE_EXCEL_COMMAND(167)
DECLARE_EXCEL_COMMAND(168)
DECLARE_EXCEL_COMMAND(169)
DECLARE_EXCEL_COMMAND(170)
DECLARE_EXCEL_COMMAND(171)
DECLARE_EXCEL_COMMAND(172)
DECLARE_EXCEL_COMMAND(173)
DECLARE_EXCEL_COMMAND(174)
DECLARE_EXCEL_COMMAND(175)
DECLARE_EXCEL_COMMAND(176)
DECLARE_EXCEL_COMMAND(177)
DECLARE_EXCEL_COMMAND(178)
DECLARE_EXCEL_COMMAND(179)
DECLARE_EXCEL_COMMAND(180)
DECLARE_EXCEL_COMMAND(181)
DECLARE_EXCEL_COMMAND(182)
DECLARE_EXCEL_COMMAND(183)
DECLARE_EXCEL_COMMAND(184)
DECLARE_EXCEL_COMMAND(185)
DECLARE_EXCEL_COMMAND(186)
DECLARE_EXCEL_COMMAND(187)
DECLARE_EXCEL_COMMAND(188)
DECLARE_EXCEL_COMMAND(189)
DECLARE_EXCEL_COMMAND(190)
DECLARE_EXCEL_COMMAND(191)
DECLARE_EXCEL_COMMAND(192)
DECLARE_EXCEL_COMMAND(193)
DECLARE_EXCEL_COMMAND(194)
DECLARE_EXCEL_COMMAND(195)
DECLARE_EXCEL_COMMAND(196)
DECLARE_EXCEL_COMMAND(197)
DECLARE_EXCEL_COMMAND(198)
DECLARE_EXCEL_COMMAND(199)
DECLARE_EXCEL_COMMAND(200)
DECLARE_EXCEL_COMMAND(201)
DECLARE_EXCEL_COMMAND(202)
DECLARE_EXCEL_COMMAND(203)
DECLARE_EXCEL_COMMAND(204)
DECLARE_EXCEL_COMMAND(205)
DECLARE_EXCEL_COMMAND(206)
DECLARE_EXCEL_COMMAND(207)
DECLARE_EXCEL_COMMAND(208)
DECLARE_EXCEL_COMMAND(209)
DECLARE_EXCEL_COMMAND(210)
DECLARE_EXCEL_COMMAND(211)
DECLARE_EXCEL_COMMAND(212)
DECLARE_EXCEL_COMMAND(213)
DECLARE_EXCEL_COMMAND(214)
DECLARE_EXCEL_COMMAND(215)
DECLARE_EXCEL_COMMAND(216)
DECLARE_EXCEL_COMMAND(217)
DECLARE_EXCEL_COMMAND(218)
DECLARE_EXCEL_COMMAND(219)
DECLARE_EXCEL_COMMAND(220)
DECLARE_EXCEL_COMMAND(221)
DECLARE_EXCEL_COMMAND(222)
DECLARE_EXCEL_COMMAND(223)
DECLARE_EXCEL_COMMAND(224)
DECLARE_EXCEL_COMMAND(225)
DECLARE_EXCEL_COMMAND(226)
DECLARE_EXCEL_COMMAND(227)
DECLARE_EXCEL_COMMAND(228)
DECLARE_EXCEL_COMMAND(229)
DECLARE_EXCEL_COMMAND(230)
DECLARE_EXCEL_COMMAND(231)
DECLARE_EXCEL_COMMAND(232)
DECLARE_EXCEL_COMMAND(233)
DECLARE_EXCEL_COMMAND(234)
DECLARE_EXCEL_COMMAND(235)
DECLARE_EXCEL_COMMAND(236)
DECLARE_EXCEL_COMMAND(237)
DECLARE_EXCEL_COMMAND(238)
DECLARE_EXCEL_COMMAND(239)
DECLARE_EXCEL_COMMAND(240)
DECLARE_EXCEL_COMMAND(241)
DECLARE_EXCEL_COMMAND(242)
DECLARE_EXCEL_COMMAND(243)
DECLARE_EXCEL_COMMAND(244)
DECLARE_EXCEL_COMMAND(245)
DECLARE_EXCEL_COMMAND(246)
DECLARE_EXCEL_COMMAND(247)
DECLARE_EXCEL_COMMAND(248)
DECLARE_EXCEL_COMMAND(249)
DECLARE_EXCEL_COMMAND(250)
DECLARE_EXCEL_COMMAND(251)
DECLARE_EXCEL_COMMAND(252)
DECLARE_EXCEL_COMMAND(253)
DECLARE_EXCEL_COMMAND(254)
DECLARE_EXCEL_COMMAND(255)
DECLARE_EXCEL_COMMAND(256)
DECLARE_EXCEL_COMMAND(257)
DECLARE_EXCEL_COMMAND(258)
DECLARE_EXCEL_COMMAND(259)
DECLARE_EXCEL_COMMAND(260)
DECLARE_EXCEL_COMMAND(261)
DECLARE_EXCEL_COMMAND(262)
DECLARE_EXCEL_COMMAND(263)
DECLARE_EXCEL_COMMAND(264)
DECLARE_EXCEL_COMMAND(265)
DECLARE_EXCEL_COMMAND(266)
DECLARE_EXCEL_COMMAND(267)
DECLARE_EXCEL_COMMAND(268)
DECLARE_EXCEL_COMMAND(269)
DECLARE_EXCEL_COMMAND(270)
DECLARE_EXCEL_COMMAND(271)
DECLARE_EXCEL_COMMAND(272)
DECLARE_EXCEL_COMMAND(273)
DECLARE_EXCEL_COMMAND(274)
DECLARE_EXCEL_COMMAND(275)
DECLARE_EXCEL_COMMAND(276)
DECLARE_EXCEL_COMMAND(277)
DECLARE_EXCEL_COMMAND(278)
DECLARE_EXCEL_COMMAND(279)
DECLARE_EXCEL_COMMAND(280)
DECLARE_EXCEL_COMMAND(281)
DECLARE_EXCEL_COMMAND(282)
DECLARE_EXCEL_COMMAND(283)
DECLARE_EXCEL_COMMAND(284)
DECLARE_EXCEL_COMMAND(285)
DECLARE_EXCEL_COMMAND(286)
DECLARE_EXCEL_COMMAND(287)
DECLARE_EXCEL_COMMAND(288)
DECLARE_EXCEL_COMMAND(289)
DECLARE_EXCEL_COMMAND(290)
DECLARE_EXCEL_COMMAND(291)
DECLARE_EXCEL_COMMAND(292)
DECLARE_EXCEL_COMMAND(293)
DECLARE_EXCEL_COMMAND(294)
DECLARE_EXCEL_COMMAND(295)
DECLARE_EXCEL_COMMAND(296)
DECLARE_EXCEL_COMMAND(297)
DECLARE_EXCEL_COMMAND(298)
DECLARE_EXCEL_COMMAND(299)
DECLARE_EXCEL_COMMAND(300)
DECLARE_EXCEL_COMMAND(301)
DECLARE_EXCEL_COMMAND(302)
DECLARE_EXCEL_COMMAND(303)
DECLARE_EXCEL_COMMAND(304)
DECLARE_EXCEL_COMMAND(305)
DECLARE_EXCEL_COMMAND(306)
DECLARE_EXCEL_COMMAND(307)
DECLARE_EXCEL_COMMAND(308)
DECLARE_EXCEL_COMMAND(309)
DECLARE_EXCEL_COMMAND(310)
DECLARE_EXCEL_COMMAND(311)
DECLARE_EXCEL_COMMAND(312)
DECLARE_EXCEL_COMMAND(313)
DECLARE_EXCEL_COMMAND(314)
DECLARE_EXCEL_COMMAND(315)
DECLARE_EXCEL_COMMAND(316)
DECLARE_EXCEL_COMMAND(317)
DECLARE_EXCEL_COMMAND(318)
DECLARE_EXCEL_COMMAND(319)
DECLARE_EXCEL_COMMAND(320)
DECLARE_EXCEL_COMMAND(321)
DECLARE_EXCEL_COMMAND(322)
DECLARE_EXCEL_COMMAND(323)
DECLARE_EXCEL_COMMAND(324)
DECLARE_EXCEL_COMMAND(325)
DECLARE_EXCEL_COMMAND(326)
DECLARE_EXCEL_COMMAND(327)
DECLARE_EXCEL_COMMAND(328)
DECLARE_EXCEL_COMMAND(329)
DECLARE_EXCEL_COMMAND(330)
DECLARE_EXCEL_COMMAND(331)
DECLARE_EXCEL_COMMAND(332)
DECLARE_EXCEL_COMMAND(333)
DECLARE_EXCEL_COMMAND(334)
DECLARE_EXCEL_COMMAND(335)
DECLARE_EXCEL_COMMAND(336)
DECLARE_EXCEL_COMMAND(337)
DECLARE_EXCEL_COMMAND(338)
DECLARE_EXCEL_COMMAND(339)
DECLARE_EXCEL_COMMAND(340)
DECLARE_EXCEL_COMMAND(341)
DECLARE_EXCEL_COMMAND(342)
DECLARE_EXCEL_COMMAND(343)
DECLARE_EXCEL_COMMAND(344)
DECLARE_EXCEL_COMMAND(345)
DECLARE_EXCEL_COMMAND(346)
DECLARE_EXCEL_COMMAND(347)
DECLARE_EXCEL_COMMAND(348)
DECLARE_EXCEL_COMMAND(349)
DECLARE_EXCEL_COMMAND(350)
DECLARE_EXCEL_COMMAND(351)
DECLARE_EXCEL_COMMAND(352)
DECLARE_EXCEL_COMMAND(353)
DECLARE_EXCEL_COMMAND(354)
DECLARE_EXCEL_COMMAND(355)
DECLARE_EXCEL_COMMAND(356)
DECLARE_EXCEL_COMMAND(357)
DECLARE_EXCEL_COMMAND(358)
DECLARE_EXCEL_COMMAND(359)
DECLARE_EXCEL_COMMAND(360)
DECLARE_EXCEL_COMMAND(361)
DECLARE_EXCEL_COMMAND(362)
DECLARE_EXCEL_COMMAND(363)
DECLARE_EXCEL_COMMAND(364)
DECLARE_EXCEL_COMMAND(365)
DECLARE_EXCEL_COMMAND(366)
DECLARE_EXCEL_COMMAND(367)
DECLARE_EXCEL_COMMAND(368)
DECLARE_EXCEL_COMMAND(369)
DECLARE_EXCEL_COMMAND(370)
DECLARE_EXCEL_COMMAND(371)
DECLARE_EXCEL_COMMAND(372)
DECLARE_EXCEL_COMMAND(373)
DECLARE_EXCEL_COMMAND(374)
DECLARE_EXCEL_COMMAND(375)
DECLARE_EXCEL_COMMAND(376)
DECLARE_EXCEL_COMMAND(377)
DECLARE_EXCEL_COMMAND(378)
DECLARE_EXCEL_COMMAND(379)
DECLARE_EXCEL_COMMAND(380)
DECLARE_EXCEL_COMMAND(381)
DECLARE_EXCEL_COMMAND(382)
DECLARE_EXCEL_COMMAND(383)
DECLARE_EXCEL_COMMAND(384)
DECLARE_EXCEL_COMMAND(385)
DECLARE_EXCEL_COMMAND(386)
DECLARE_EXCEL_COMMAND(387)
DECLARE_EXCEL_COMMAND(388)
DECLARE_EXCEL_COMMAND(389)
DECLARE_EXCEL_COMMAND(390)
DECLARE_EXCEL_COMMAND(391)
DECLARE_EXCEL_COMMAND(392)
DECLARE_EXCEL_COMMAND(393)
DECLARE_EXCEL_COMMAND(394)
DECLARE_EXCEL_COMMAND(395)
DECLARE_EXCEL_COMMAND(396)
DECLARE_EXCEL_COMMAND(397)
DECLARE_EXCEL_COMMAND(398)
DECLARE_EXCEL_COMMAND(399)
DECLARE_EXCEL_COMMAND(400)
DECLARE_EXCEL_COMMAND(401)
DECLARE_EXCEL_COMMAND(402)
DECLARE_EXCEL_COMMAND(403)
DECLARE_EXCEL_COMMAND(404)
DECLARE_EXCEL_COMMAND(405)
DECLARE_EXCEL_COMMAND(406)
DECLARE_EXCEL_COMMAND(407)
DECLARE_EXCEL_COMMAND(408)
DECLARE_EXCEL_COMMAND(409)
DECLARE_EXCEL_COMMAND(410)
DECLARE_EXCEL_COMMAND(411)
DECLARE_EXCEL_COMMAND(412)
DECLARE_EXCEL_COMMAND(413)
DECLARE_EXCEL_COMMAND(414)
DECLARE_EXCEL_COMMAND(415)
DECLARE_EXCEL_COMMAND(416)
DECLARE_EXCEL_COMMAND(417)
DECLARE_EXCEL_COMMAND(418)
DECLARE_EXCEL_COMMAND(419)
DECLARE_EXCEL_COMMAND(420)
DECLARE_EXCEL_COMMAND(421)
DECLARE_EXCEL_COMMAND(422)
DECLARE_EXCEL_COMMAND(423)
DECLARE_EXCEL_COMMAND(424)
DECLARE_EXCEL_COMMAND(425)
DECLARE_EXCEL_COMMAND(426)
DECLARE_EXCEL_COMMAND(427)
DECLARE_EXCEL_COMMAND(428)
DECLARE_EXCEL_COMMAND(429)
DECLARE_EXCEL_COMMAND(430)
DECLARE_EXCEL_COMMAND(431)
DECLARE_EXCEL_COMMAND(432)
DECLARE_EXCEL_COMMAND(433)
DECLARE_EXCEL_COMMAND(434)
DECLARE_EXCEL_COMMAND(435)
DECLARE_EXCEL_COMMAND(436)
DECLARE_EXCEL_COMMAND(437)
DECLARE_EXCEL_COMMAND(438)
DECLARE_EXCEL_COMMAND(439)
DECLARE_EXCEL_COMMAND(440)
DECLARE_EXCEL_COMMAND(441)
DECLARE_EXCEL_COMMAND(442)
DECLARE_EXCEL_COMMAND(443)
DECLARE_EXCEL_COMMAND(444)
DECLARE_EXCEL_COMMAND(445)
DECLARE_EXCEL_COMMAND(446)
DECLARE_EXCEL_COMMAND(447)
DECLARE_EXCEL_COMMAND(448)
DECLARE_EXCEL_COMMAND(449)
DECLARE_EXCEL_COMMAND(450)
DECLARE_EXCEL_COMMAND(451)
DECLARE_EXCEL_COMMAND(452)
DECLARE_EXCEL_COMMAND(453)
DECLARE_EXCEL_COMMAND(454)
DECLARE_EXCEL_COMMAND(455)
DECLARE_EXCEL_COMMAND(456)
DECLARE_EXCEL_COMMAND(457)
DECLARE_EXCEL_COMMAND(458)
DECLARE_EXCEL_COMMAND(459)
DECLARE_EXCEL_COMMAND(460)
DECLARE_EXCEL_COMMAND(461)
DECLARE_EXCEL_COMMAND(462)
DECLARE_EXCEL_COMMAND(463)
DECLARE_EXCEL_COMMAND(464)
DECLARE_EXCEL_COMMAND(465)
DECLARE_EXCEL_COMMAND(466)
DECLARE_EXCEL_COMMAND(467)
DECLARE_EXCEL_COMMAND(468)
DECLARE_EXCEL_COMMAND(469)
DECLARE_EXCEL_COMMAND(470)
DECLARE_EXCEL_COMMAND(471)
DECLARE_EXCEL_COMMAND(472)
DECLARE_EXCEL_COMMAND(473)
DECLARE_EXCEL_COMMAND(474)
DECLARE_EXCEL_COMMAND(475)
DECLARE_EXCEL_COMMAND(476)
DECLARE_EXCEL_COMMAND(477)
DECLARE_EXCEL_COMMAND(478)
DECLARE_EXCEL_COMMAND(479)
DECLARE_EXCEL_COMMAND(480)
DECLARE_EXCEL_COMMAND(481)
DECLARE_EXCEL_COMMAND(482)
DECLARE_EXCEL_COMMAND(483)
DECLARE_EXCEL_COMMAND(484)
DECLARE_EXCEL_COMMAND(485)
DECLARE_EXCEL_COMMAND(486)
DECLARE_EXCEL_COMMAND(487)
DECLARE_EXCEL_COMMAND(488)
DECLARE_EXCEL_COMMAND(489)
DECLARE_EXCEL_COMMAND(490)
DECLARE_EXCEL_COMMAND(491)
DECLARE_EXCEL_COMMAND(492)
DECLARE_EXCEL_COMMAND(493)
DECLARE_EXCEL_COMMAND(494)
DECLARE_EXCEL_COMMAND(495)
DECLARE_EXCEL_COMMAND(496)
DECLARE_EXCEL_COMMAND(497)
DECLARE_EXCEL_COMMAND(498)
DECLARE_EXCEL_COMMAND(499)
DECLARE_EXCEL_COMMAND(500)
DECLARE_EXCEL_COMMAND(501)
DECLARE_EXCEL_COMMAND(502)
DECLARE_EXCEL_COMMAND(503)
DECLARE_EXCEL_COMMAND(504)
DECLARE_EXCEL_COMMAND(505)
DECLARE_EXCEL_COMMAND(506)
DECLARE_EXCEL_COMMAND(507)
DECLARE_EXCEL_COMMAND(508)
DECLARE_EXCEL_COMMAND(509)
DECLARE_EXCEL_COMMAND(510)
DECLARE_EXCEL_COMMAND(511)
